import api from "@/api";
import { ContentType } from "@/enums/message";
import { defineStore } from "pinia";
import { stringify, parse } from "zipson";

export const useModelStore = defineStore("modelStore", {
  state: () => {
    return {
      textModel: "",
      imageModel: "",
    };
  },
  getters: {},
  actions: {
    async initModel() {
      if (!this.textModel) {
        const res = await api.model.listModel(ContentType.TEXT);
        if (res.code === 200) {
          this.textModel = res.data[0].value;
        }
      }
      if (!this.imageModel) {
        const res = await api.model.listModel(ContentType.IMAGE);
        if (res.code === 200) {
          this.imageModel = res.data[0].value;
        }
      }
    },
  },
  persist: {
    serializer: {
      deserialize: parse,
      serialize: stringify,
    },
    afterRestore: (ctx) => {
      console.log(`刚刚恢复完 '${ctx.store.$id}'`);
      console.log(ctx);
    },
  },
});
